<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>阳光成单系统</title>
	</head>
	<script src="../assets/layui.js" charset="utf-8"></script>
	<script src="../js/x-layui.js" charset="utf-8"></script>

	<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css" />

	<link rel="stylesheet" type="text/css" href="../css/font-awesome.min.css" />
	<link rel="stylesheet" type="text/css" href="../css/style.css" />
	<link rel="stylesheet" type="text/css" href="../css/chartist-custom.css" />

	<link rel="stylesheet" type="text/css" href="../css/main.css" /> 
	<link rel="stylesheet" type="text/css" href="../css/demo.css" />
	<link rel="stylesheet" type="text/css" href="../css/public.css" />
	<link rel="stylesheet" type="text/css" href="../css/jquery.datetimepicker.css" />



	<!--导入核心bootstrap css样式-->
	<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css" />
	<!--导入jQuery-->
	<script src="../js/jquery-3.2.0.min.js" type="text/javascript" charset="utf-8"></script>
	<!--导入核心Bootstrap js-->
	<script src="../js/bootstarp-3.3.7/js/bootstrap.min.js" type="text/javascript" charset="utf-8"></script>
	<link rel="stylesheet" type="text/css" href="../js/bootstarp-table-1.11.1/bootstrap-table.min.css" />
	<script src="../js/bootstarp-table-1.11.1/bootstrap-table.min.js" type="text/javascript" charset="utf-8"></script>
	<script src="../js/bootstarp-table-1.11.1/bootstrap-table-zh-CN.min.js" type="text/javascript" charset="utf-8"></script>

	</style>

	<script>
		$(function() { //, headers: { 'x-requested-with': 'XMLHttpRequest' }
			$.ajaxSetup({
				crossDomain: true,
				xhrFields: {
					withCredentials: true
				}
			});
		});
	</script>

	<script type="text/javascript">
		var url = window.location.search
		var str = url.split('?')[1];
		var str2 = str.split('&');
		var str3 = str2[0];
		var str4 = str2[1];
		var pfzje = 0;
		var cfzje = 0;
		$(function() {
			$.ajax({
				type: "post",
				url: "http://127.0.0.1:8099/getBatchesOfAll",
				data: 'batches_of_inventory_id=' + str3,
				success: function(data) {

					for(i = 0; i < data.length; i++) {

						pfzje += data[i].purchase_trade_total_amount;
						cfzje += data[i].purchase_prescription_total_amount;
					}

					$("#pf").html(pfzje);
					$("#cf").html(cfzje);
				}
			});

			$.ajax({
				type: "post",
				url: "http://127.0.0.1:8099/getBatchesOfAll",
				data: 'batches_of_inventory_id=' + str3,
				success: function(n) {

					for(i = 0; i < n.length; i++) {

						$("#tabcg").append($("<tr><td><input type='hidden' class='iid' value='" + n[i].medicines_id + "' /></td> <td >" + n[i].medicines_name + "</td><td>" + n[i].guige + "</td><td>" + n[i].medicines_class + "</td><td><input type='hidden' class='nnum' value='" + n[i].purchase_num + "' />" + n[i].purchase_num + "</td><td><input type='hidden' class='uunit' value='" + n[i].unit + "' />" + n[i].unit + "</td><td><input type='hidden' class='pprice' value='" + n[i].purchase_trade_price + "' />" + n[i].purchase_trade_price + "</td><td><input type='hidden' class='ppric' value='" + n[i].purchase_prescription_price + "' />" + n[i].purchase_prescription_price + "</td><td><input type='hidden' class='aam' value='" + n[i].purchase_trade_total_amount + "' />" + n[i].purchase_trade_total_amount + "</td><td><input type='hidden' class='amou' value='" + n[i].purchase_prescription_total_amount + "' />" + n[i].purchase_prescription_total_amount + "</td><td><button class='layui-btn layui-btn-small layui-btn-danger layui-btn-radius' type='button' onclick='deleteRow(" + n[i].purchase_id + ")'>删除</button></td></tr>"))
					}
				}
			});

			if(str4 == 1) {
				$("#shen").prop('disabled', true)
			}
			$.ajax({
				type: "post",
				url: "http://127.0.0.1:8099/BatchesOfsidsid",
				data: "batches_of_inventory_id=" + str,
				dataType: "json",
				success: function(data) {
					$("#tim").val(data.batches_of_inventory_number)
					$("#zdr").val(data.purchasing_agent_id)
					$("#gys").val(data.supplier_name)
					$("#zdrq").val(data.batches_of_inventory_date)
					$("#gysid").val(data.supplier_id)
				}
			});

		});

		function queryParams() {
			return {
				'batches_of_inventory_id': str3
			}
		}

		function deleteRow(purchaseId) {
			alert("确定删除？")
			$.ajax({
				type: "post",
				url: "http://127.0.0.1:8099/del",
				data: "purchase_id=" + purchaseId,
				dataType: "jsong ",
			});
			var pzje = 0;
			var czje = 0;

			$.ajax({
				type: "post",
				url: "http://127.0.0.1:8099/getBatchesOfAll",
				data: 'batches_of_inventory_id=' + str3,
				success: function(data) {

					for(i = 0; i < data.length; i++) {

						pzje += data[i].purchase_trade_total_amount;
						czje += data[i].purchase_prescription_total_amount;
					}

					$("#pf").html(pzje);
					$("#cf").html(czje);
					window.location.reload();
				}
			});
		}

		function sh() {
			$.ajax({
				type: "post",
				url: "http://127.0.0.1:8099/upBatchesOfs",
				data: "batches_of_inventory_id=" + str,
				dataType: "json",
				success: function(data) {

				}
			});
			var numbb = new Array();
			$(".iid").each(function(i) {
				var sdfd = {
					"hmr_id": $(".iid:eq(" + i + ")").val(),
					"inventory_num": $(".nnum:eq(" + i + ")").val(),
					"inventory_unit": $(".uunit:eq(" + i + ")").val(),
					"inventory_trade_price": $(".pprice:eq(" + i + ")").val(),
					"inventory_prescription_price": $(".ppric:eq(" + i + ")").val(),
					"inventory_trade_total_amount": $(".aam:eq(" + i + ")").val(),
					"inventory_prescription_total_amount": $(".amou:eq(" + i + ")").val()

				}
				numbb.push(sdfd);
			})
			$.ajax({
				type: "post",
				url: "http://127.0.0.1:8099/cgrk/addinslist",
				data: JSON.stringify(numbb),
				dataType: "json",
				contentType: "application/json",
				success: function(data) {

				}
			});
			var a = $("#tim").val();
			$.ajax({
				type: "post",
				url: "http://127.0.0.1:8099/cgrk/addin",
				data: "batches_of_inventory_number=" + a + "&batches_of_inventory_total_money=" + $("#pf").html() + "&supplier_id=" + $("#gysid").val() + "&batches_of_inventory_date=" + $("#zdrq").val(),
				success: function(data) {

				}
			});

			window.location = 'audit-list.html'
		}
	</script>

	<body>
		<div class="main">
			<!-- MAIN CONTENT -->
			<div class="main-content">
				<div class="container-fluid">

					<div class="pd10 panel mb10 clearfix ftr">
						<input name="supplier_id" id="gysid" type="hidden" />
						<form id="ffr">

							<div class="fublBox l flh34"> <span class="mr20">单据号：<input type='text' name="batches_of_inventory_number" id="tim" style='border: 0px; width: 120px; outline: none; cursor: pointer;' readonly='readonly' /></span>
								<span class="mr20">制单人：<input type='text' id="zdr" name="zdr" style='border: 0px; width: 50px; outline: none; cursor: pointer;' readonly='readonly' /></span>
								<span class="mr20">供应商：<input type='text' id="gys" style='border: 0px; width: 80px; outline: none; cursor: pointer;' readonly='readonly' /></span>
								<span class="mr10">制单日期：<input type='text' id="zdrq" name="batches_of_inventory_date" style='border: 0px; width: 100px; outline: none; cursor: pointer;' readonly='readonly' /></span></div>
							<button type="button" class="btn btn-primary ml10" id="shen" onclick="sh()">审核</button>
							<a type="button" href="audit-list.html" class="btn btn-info ml10">返回</a>
						</form>
					</div>
					<div class="flh34 mb10 ftr">
						<span>批发总金额：<span class="red purchase_trade_total_amount" id="pf"></span></span> <span class="ml20">处方总金额：<span
                    class="red purchase_prescription_total_amount" id="cf"></span></span>
					</div>

					<div class="panel">
						<div class="pd10">
							<table class="table drugsTable ftc" id="tabcg">
								<tr>
									<td></td>
									<td>药品名称</td>
									<td>规格</td>
									<td>药瓶分类</td>
									<td>数量</td>
									<td>单位</td>
									<td>批发价</td>
									<td>处方价</td>
									<td>批发额</td>
									<td>处方额</td>
									<td>操作</td>
								</tr>

							</table>
						</div>
						<div class="paging mt20 mb20 ftc list_page_box">
						</div>
					</div>
				</div>
			</div>
		</div>

	</body>

</html>